package registration;

import javax.servlet.http.*;
import org.apache.struts.action.*;
import java.util.*;
import OnlineExam.db.*;


/** 
 *   Handles User Confirmation
 */

public final class ConfirmRegistrationAction extends Action
{

  	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
						HttpServletResponse response)
	{
		try
		{
			ConfirmRegistrationForm confReg = (ConfirmRegistrationForm)form;

			List list = DBUtil.select ("User", "registration.User", "EmailId", confReg.getEmailId(), "Password", confReg.getPassword());
			
			User u = (User)list.listIterator().next();
			//
			//if there is no such user, go to registration page.
			//
			if (u.getStatus().equals("confirmed"))
					return mapping.findForward("confirmed");
			
			u.setStatus("confirmed");
			DBUtil.update (u);

   		 	return (mapping.findForward("success"));
		}
		catch (DBException e)
		{
			System.out.println ("The Exception....." + e);
			return (mapping.findForward("error"));
		}
  	}
}
